import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_rx/get_rx.dart';
import 'package:tot_android_flutter/base/keep_alive_wrapper.dart';
import 'package:tot_android_flutter/pages/tabpage/tree/tree_page.dart';

import '../tabpage/home/home_page.dart';
import '../tabpage/mine/mine_page.dart';
import '../tabpage/project/project_page.dart';

class IndexController extends GetxController {
  RxInt currentIndex = 0.obs;

  final PageController pageController = PageController(initialPage: 0);

  final List<String> _titles = ["首页", "项目", "广场", "我的"];
  final List<Widget> _navIcons = [
    const Icon(Icons.home),
    const Icon(Icons.ac_unit),
    const Icon(Icons.animation),
    const Icon(Icons.verified_user_rounded)
  ];

  final List<Widget> pages = [
    KeepAliveWrapper(child: HomePage()),
    KeepAliveWrapper(child: ProjectPage()),
    KeepAliveWrapper(child: TreePage()),
    const KeepAliveWrapper(child: MinePage()),
  ];

  List<BottomNavigationBarItem> generateBottomNavList() {
    return List.generate(_titles.length, (index) {
      return BottomNavigationBarItem(
        icon: _navIcons[index],
        label: _titles[index],
        backgroundColor: Colors.blue,
      );
    });
  }

  void setCurrentIndex(index) {
    currentIndex.value = index;
    update();
  }
}
